import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_first/components/FoodDetail%20.dart';

class MTFoodItem extends StatelessWidget {
  const MTFoodItem({Key? key, required this.foodItem}) : super(key: key);
  final Map<String, dynamic> foodItem;

  Widget getleft() {
    return Container(
      margin: EdgeInsets.all(10),
      child: ClipRRect(
        borderRadius: BorderRadius.circular(5),
        child: Image.network(foodItem["picture"],
            width: 100, height: 100, fit: BoxFit.cover),
      ),
    );
  }

  Widget getRight() {
    return Expanded(
        child: Padding(
      padding: EdgeInsets.only(top: 10, bottom: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          Text(
            foodItem["name"],
            style: TextStyle(fontWeight: FontWeight.w600, fontSize: 20),
          ),
          Text(
            '月销量${foodItem["month_saled"]} ${foodItem["like_ratio_desc"]}',
            style: TextStyle(fontWeight: FontWeight.w500, fontSize: 14),
          ),
          Text(
            foodItem["price"].toString(),
            style: TextStyle(
                fontWeight: FontWeight.w600, fontSize: 14, color: Colors.amber),
          )
        ],
      ),
    ));
  }

  Widget getChild() {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [getleft(), getRight()],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        // Navigator.push(context,
        //     MaterialPageRoute(builder: (BuildContext context) {
        //   return const FoodDetail();
        // }));
        Navigator.pushNamed(context, "TabBarPage");
      },
      child: getChild(),
    );
  }
}
